<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新增修改部门')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>工号：</p>
                            <input type="text" name="badge"/>
                        </li>
                        <li>
                            <p>姓名：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addEditDep()">
                <i class="fa fa-plus"></i> 添加部门
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>

<script th:inline="javascript">
    var prefix = ctx + 'depart/admin';
    $(function () {
        queryData();
    })

    function queryData() {
        var columns = [];
        var checkbox = {checkbox: true};
        var depCode = {field: 'depCode', title: '部门代码'};
        var title = {field: 'title', title: '部门名称'};
        var depAbbr = {field: 'depAbbr', title: '部门简称'};
        var DepGradeTitle = {field: 'DepGradeTitle', title: '部门级别'};
        var DepTypeTitle = {field: 'DepTypeTitle', title: '部门类型'};
        var compTitle = {field: 'compTitle', title: '所属公司'};
        var AdminIdTitle = {field: 'AdminIdTitle', title: '行政上级部门'};
        var funcationIdTitle = {field: 'funcationIdTitle', title: '职能上级部门'};
        var DirectorName = {field: 'DirectorName', title: '部门负责人'};
        var Director2Name = {field: 'Director2Name', title: '部门分管领导'};
        var DepCostTitle = {field: 'DepCostTitle', title: '成本中心'};
        var EffectDate = {field: 'EffectDate', title: '成立日期'};
        var remark = {field: 'remark', title: '备注'};

        columns.push(checkbox, depCode, title, depAbbr, DepGradeTitle, DepTypeTitle, compTitle, AdminIdTitle);
        columns.push(funcationIdTitle, DirectorName, Director2Name, DepCostTitle, EffectDate, remark);

        var options = {
            code: "depId",
            uniqueId: "depId",
            url: prefix + '/findEditDep',
            modalName: "添加修改部门",
            height: $(window).height() - 110,
            columns: columns
        };
        $.table.init(options);
    }

    function addEditDep() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        }
        var allDep = "";
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allDep += row[i].depId
            } else {
                allDep += row[i].depId + ","

            }
        }

        $.ajax({
            async: false,
            url: prefix + "/addEditDep?type=2",
            data: {
                "allDep": allDep
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                //todo 这里需要判断data返回值
                if (data.code == 0) {
                    $.modal.alertWarning("添加成功！");
                    $.modal.close();
                    $.modal.reload();
                } else if (data.code == 500) {
                    $.modal.alertWarning("服务繁忙");
                } else {
                    $.modal.alertWarning(data.message);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function submitHandler() {
        addEditDep();
    }


</script>
</body>
</html>